# stories/management/commands/init_sensitive_words.py
from django.core.management.base import BaseCommand
from stories.models import SensitiveWord

class Command(BaseCommand):
    help = '初始化敏感词列表'

    def handle(self, *args, **options):
        # 初始化敏感词列表
        sensitive_words = [
            '暴力', '黄色', '非法', '不利于社会稳定',
            '色情', '赌博', '毒品', '反政府',
            '恐怖主义', '极端主义', '分裂主义',
            '骂人', '脏话', '侮辱', '诽谤'
        ]

        created_count = 0
        for word in sensitive_words:
            obj, created = SensitiveWord.objects.get_or_create(
                word=word,
                defaults={'is_active': True}
            )
            if created:
                created_count += 1

        self.stdout.write(
            self.style.SUCCESS(
                f'成功初始化 {created_count} 个敏感词'
            )
        )